package com.cn.lotary.util;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 *
 *
 * get system configuration parameter<br/>
 *
 * required :<br/>
 *
 * email_from<br/>
 *
 *
 * email_to<br/>
 *
 *
 * mail_transport_protocol<br/>
 *
 * mail_smtp_host<br/>
 *
 * mail_smtp_port<br/>
 *
 * mail_smtp_port<br/>
 * 
 * debug<br/>
 *
 *
 * @author Jason
 */
public class SystemConfig {

    /**
     * Properties file path: config.properties under the classes
     *
     *
     * config.properties the necessary parameters
     *
     * project_name=**
     *
     * @return Properties
     */
    private static final String MESSAGE_BUNDLE = "config";
    private static final ResourceBundle BUNDLE = init();

    private static ResourceBundle init() {
        try {
            return ResourceBundle.getBundle(MESSAGE_BUNDLE);
        } catch (NullPointerException e) {
            LoggerUtils.error(e);
        } catch (MissingResourceException e) {
            LoggerUtils.error(e);
        }
        return null;
    }

    public static String getValue(String key) {
        try {
            return BUNDLE.getString(key);
        } catch (NullPointerException e) {
            LoggerUtils.error(e);
        } catch (MissingResourceException e) {
            LoggerUtils.error(e);
        } catch (ClassCastException e) {
            LoggerUtils.error(e);
        }
        return key;
    }
    public static final String EMAIL_FROM = getValue("email_from");
    public static final Boolean DEBUG = Boolean.valueOf(getValue("debug"));
    public static final Boolean send_exception_email = Boolean.valueOf(getValue("send_exception_email"));
    public static final String EMAIL_TO = getValue("email_to");
    public static final String MAIL_TRANSPORT_PROTOCOL = getValue("mail_transport_protocol");
    public static final String MAIL_SMTP_HOST = getValue("mail_smtp_host");
    public static final String MAIL_SMTP_PORT = getValue("mail_smtp_port");
    public static final String PROJECT_NAME = getValue("project_name");    
}
